﻿using Microsoft.SemanticKernel.Connectors.AI.OpenAI;
using Microsoft.SemanticKernel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SemanticKernelDemo {
    public static class BaseDemo {
        public static async Task<string> Run() {
            var builder = new KernelBuilder();

            var (useAzureOpenAI, model, azureEndpoint, apiKey, orgId) = Settings.LoadFromFile();
            
            builder.WithOpenAIChatCompletionService(model, apiKey, orgId);

            var kernel = builder.Build();

            string skPrompt = @"
            {{$input}}

            Give me the TLDR in 5 words          ";

            var textToSummarize = @"
                1) A robot may not injure a human being or, through inaction,
                allow a human being to come to harm.

                2) A robot must obey orders given it by human beings except where
                such orders would conflict with the First Law.

                3) A robot must protect its own existence as long as such protection
                does not conflict with the First or Second Law.
            ";

            var tldrFunction = kernel.CreateSemanticFunction(skPrompt, requestSettings: new OpenAIRequestSettings { MaxTokens = 2000, Temperature = 0.2, TopP = 0.5 });

            var summaryResult = await kernel.RunAsync(textToSummarize, tldrFunction);
            var summary = summaryResult.GetValue<string>();

            Console.WriteLine(summary);
            return "";
        }
    }
}
